package com.xinke.juc.case03;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author：xinke
 * @Date：2025/9/30
 * @Desc: 打断正常运行的线程, 不会清空打断状态
 */
@Slf4j
public class TestInterrupt02 {
    public static void main(String[] args) throws InterruptedException {
        Thread t2 = new Thread(() -> {
            while (true) {
                Thread currentThread = Thread.currentThread();
                boolean interrupted = currentThread.isInterrupted();
                if(interrupted){
                    log.info("打断状态2：{}",interrupted);
                    break;
                }
            }
        }, "t2");
        t2.start();
        Thread.sleep(500);
        t2.interrupt();
        log.info("打断状态1：{}", t2.isInterrupted());
    }
}
